package com.google.code.ptrends.excel.entities;

public class CellStyle {
	
	private String background;	
	private String foreground;
	private boolean isBold;
	private boolean isItalic;
	private boolean isUnderlined;
	private int fontSize;
	private int fHashCode;
	
	public CellStyle(){}
	
	public CellStyle(String background, String foreground, int fontSize, boolean isBold, boolean isItalic, boolean isUnderlined){
		this.background = background;
		this.foreground = foreground;
		this.fontSize = fontSize;
		this.isBold = isBold;
		this.isItalic = isItalic;
		this.isUnderlined = isUnderlined;
	}
	
	public String getBackground() {
		return background;
	}
	
	public void setBackground(String background) {
		this.background = background;
	}
	
	public String getForeground() {
		return foreground;
	}
	
	public void setForeground(String foreground) {
		this.foreground = foreground;
	}
	
	public boolean isBold() {
		return isBold;
	}
	
	public void setBold(boolean isBold) {
		this.isBold = isBold;
	}
	
	public boolean isItalic() {
		return isItalic;
	}
	public void setItalic(boolean isItalic) {
		this.isItalic = isItalic;
	}
	
	public boolean isUnderlined() {
		return isUnderlined;
	}
	
	public void setUnderlined(boolean isUnderlined) {
		this.isUnderlined = isUnderlined;
	}
	
	@Override
	public boolean equals(Object arg0) {
		if ( arg0 == null)
			return false;
		
		if (!(arg0 instanceof CellStyle))
			return false;
		CellStyle obj = (CellStyle)arg0;
		boolean result = isBold == obj.isBold();
		result &= isItalic == obj.isItalic();
		result &= isUnderlined == obj.isUnderlined();
		
		if (background != null){
			result &= background.equals(obj.getBackground());
		}
		else{
			result &= obj.getBackground() == null;
		}
		
		if (foreground != null){
			result &= foreground.equals(obj.getForeground());
		}
		else{
			result &= obj.getForeground() == null;
		}
		
		result &= fontSize == obj.getFontSize();
		
		return result;
	}
	
	@Override
	public int hashCode() {
		if ( fHashCode == 0 ){
			int ival = isBold ? 1 : 0;
			fHashCode = 7 + 11 * ival;
			
			ival = isItalic ? 1 : 0;
			fHashCode ^= 13 * ival;
			
			ival = isUnderlined ? 1 : 0;
			fHashCode ^= 17 * ival;
			
			if ( background != null){
				fHashCode ^= 23 * background.hashCode();
			}
			if (foreground != null){
				fHashCode ^= 29 * foreground.hashCode();
			}
			
			fHashCode ^= 31 * fontSize;
		}
		
		return fHashCode;
	}

	public void setFontSize(int fontSize) {
		this.fontSize = fontSize;
	}

	public int getFontSize() {
		return fontSize;
	}
	
}
